import { CreateTokenDto } from '@/common/dto/CreateTokenDto';
import { ResultData } from '@/common/dto/result';
import { ApiResult } from '@/decorators/apiResult-decorators';
import { Body, Controller, Get, Post, Query, Req } from '@nestjs/common';
import { ApiBearerAuth, ApiExtraModels, ApiOperation, ApiTags } from '@nestjs/swagger';
import { UserDto, UserListDto } from '@/modules/users/dto/UserDto';
import { UsersService } from './users.service';
// import { AllowAnon } from '@/decorators/allow-anon.decortors';
import { UserEntity } from './users.entity';

@ApiTags('员工管理')
// ApiExtraModels 作用是指定定义的model可以在swagger文档中使用
@ApiExtraModels(ResultData, CreateTokenDto, UserEntity, UserListDto)
@Controller('user')
export class UsersController {
  constructor(private readonly usersService: UsersService) {}

  @Post('create')
  // @ApiOperation 指定接口的名称、描述、参数、返回值
  @ApiOperation({ summary: '创建员工' })
  @ApiResult(UserEntity)
  @ApiBearerAuth()
  async create(@Body() user: UserDto): Promise<ResultData> {
    return this.usersService.create(user);
  }
  @Get('list')
  @ApiOperation({ summary: '获取员工列表' })
  @ApiResult(UserEntity)
  @ApiBearerAuth()
  async userList(@Query() user: UserListDto): Promise<ResultData> {
    // 支持各种模糊搜索 排序
    return this.usersService.userList(user);
  }
}
